<?php
/**
 * Created by Command.
 * User: Vito
 */

namespace app\admin\curd\polling_record;

use app\common\curd\Index;
use app\model\Attachment;
use think\db\Query;
class PollingRecordIndex extends Index
{
    /**
     * 关键词查询指定字段
     * @var string[]
     */
    protected $keywordQueryArgs = [];
    //追加标签数据
    protected $labelCallback = [
        'get_state_enum' => ['name' => '状态'],
    ];
    //查询条件
    protected $where = [];
    //字段
    protected $field = [];
    //排除字段
    protected $withoutField = false;
    //关联
    protected $with = ['repair_user'];
    /**
     * 需要查询条件的字段
     * 数据库字段和参数字段名不一样 'db_field' => 'param_field'
     * 数据库字段和参数字段名一样 'field'
     * @var array
     */
    protected $queryField = [];

    protected function formatMiddleware($next){

        $response = $next();
        
        // halt($respose);
        foreach ($response as $key => $value) {
            // print_r($value['fault_img']);
            // die;
            //   $fault_img = explode(",",$value['fault_img']);

            // $response[$key]['fault_list'] = [];
            $response[$key]['img_list'] = $this->getImgList($value['img']);

            // $response[$key]['complete_list'] = $this->getImgList($value['complete_img']);
            
            // print_r($response[$key]['fault_url']['id']);
            // die;
        //   print_r(json_decode(Attachment::getImg($where)));
        //   die;
        }
        return $response;
    }

    /**
     * @Description: 获取图片组
     * @author: xiayu <cb1071403016@126.com>
     * @Date: 2023-10-25 14:10:35
     * @param[in] $value
     * @version: 1.0.0
     * @return 
     */    
    protected function getImgList($value){
        $attachment = new Attachment;
        // $res = [];
        $where[] = ['url', 'in', $value];
        $res = json_decode($attachment->getImg($where),true);
        return $res;
    }
}